﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using OtfPG.Core;
using OtfPG.Objects;

namespace OtfPG
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Generation _oftGeneration = null;
        protected Generation OftGeneration
        {
            get
            {
                if (_oftGeneration == null)
                    _oftGeneration = new Generation();

                return _oftGeneration;
            }
        }
        

        public MainWindow()
        {
            InitializeComponent();
        }

        private void GeneratePW_Click(object sender, RoutedEventArgs e)
        {
            Options passwordOptions = new Options(chkIncludeSpecialCharacters.IsChecked.Value, chkDisplayResult.IsChecked.Value, chkReduceLength.IsChecked.Value);

            int passwordLength = 0;
            if (int.TryParse(txtPasswordLength.Text, out passwordLength))
                passwordOptions.PasswordLength = passwordLength;

            OftGeneration.GeneratePassword(pbUserPassPhrase.Password, passwordOptions);

            if(passwordOptions.DisplayResult)
                PWResult.Text = OftGeneration.GeneratedPassword;
        }

        private void chkDisplayResult_Click(object sender, RoutedEventArgs e)
        {
            if (chkDisplayResult.IsChecked.Value)
                PWResult.Text = OftGeneration.GeneratedPassword;
            else
                PWResult.Text = string.Empty;
        }



    }
}
